package com.tencent.wxcloudrun.controller;

import com.tencent.wxcloudrun.model.Coupon;
import com.tencent.wxcloudrun.response.R;
import com.tencent.wxcloudrun.service.CouponUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * ClassName: CouponUserController
 * Package: com.tencent.wxcloudrun.controller
 * Description:
 *
 * @Date: 2023/1/22 8:34 AM
 * @Author: wht
 */
@Slf4j
@RestController
//@RestController = @Controller + @ResponseBody
@RequestMapping("/admin")
public class CouponUserController {
    @Autowired
    CouponUserService couponUserService;

//    @PutMapping("/addOneCouponUser")
//    public <T> R<T> addOneCouponUser(@RequestBody Coupon coupon) {
//        couponUserService.addOneCouponUser(coupon);
//        return R.successMsg("添加成功！");
//    }
    @PutMapping("/addOneCouponUser")
    public <T> R<T> addOneCouponUser(@RequestBody Map<String, Integer> bodyMap) {
        couponUserService.addOneCouponUser(bodyMap.get("user_id"), bodyMap.get("coupon_cate_id"));
        return R.successMsg("添加成功！");
    }
    @PatchMapping("/updateOneCouponUserById")
    public <T> R<T> updateOneCouponUserById(@RequestBody Coupon coupon) {
        couponUserService.updateOneCouponUserById(coupon);
        return R.successMsg("修改成功！");
    }

    @PostMapping("/getCouponUserList")
    public <T> R<T> getCouponUserList(@RequestBody Coupon coupon) {
        List<Coupon> couponList = couponUserService.getCouponUserList(coupon);
        return R.successData(couponList);
    }
}
